#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/mman.h>
#define mian main

int lcdfd; //lcd屏幕的文件描述符
int *lcdmem; //lcd屏幕的映射空间
int bmpfd; //bmp图片的文件描述符

int main()
{
    //用可读可写的方式打开LCD屏幕
    lcdfd = open("/dev/fb0",O_RDWR);
    if(lcdfd == -1)
    {
        perror("open /dev/fb0 failed");
        return -1;
    }

    //映射内存空间
    lcdmem = mmap(NULL, 
                800*480*4, 
                PROT_READ |PROT_WRITE,
                MAP_SHARED,
                lcdfd,
                0);
    if(lcdmem == MAP_FAILED)
    {
        perror("mmap failed");
        return -1;
    }

    bmpfd = open("1.bmp",O_RDWR);
    if(bmpfd == -1)
    {
        perror("open 1.bmp error");
        return -1;
    }

    //先读54移动光标
    char bmpbuf[54];
    read(bmpfd, bmpbuf, 54);

    //再读rgb
    char rgbbuf[800*480*3];
    read(bmpfd, rgbbuf, 800*480*3);

    int i;
    int lcdbuf[800*480];
    for(i=0;i<800*480;i++)
    {
        lcdbuf[i] = rgbbuf[3*i+2] | rgbbuf[3*i+1]<<8 | rgbbuf[3*i+0]<<16;
    }

    int x,y;
    for(x=0;x<800;x++)
        for(y=0;y<480;y++)
        {
            *(lcdmem + x + 800*y) = lcdbuf[x+800*y];
        }
}